namespace QMVnSoft.Opening
{
    using QMVnSoft;
    using QMVnSoft.Controls;
    using QMVnSoft.DAL;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    public class FormCDZ3Editor : FormOpenningEditor
    {
        private IContainer components;
        private LabelControl lblMa_Sp;
        private LabelControl lblMa_Yt;
        private LabelControl lblTien;
        private TextNumeric txtDu_Cuoi;
        private TextSearch txtMa_Sp;
        private TextSearch txtMa_Yt;
        private TextControl txtTen_Sp;
        private TextControl txtTen_Yt;

        public FormCDZ3Editor()
        {
            this.InitializeComponent();
        }

        public FormCDZ3Editor(object poUserDefined1, object poUserDefined2, object poUserDefined3) : base(poUserDefined1, poUserDefined2, poUserDefined3)
        {
            this.InitializeComponent();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormCDZ3Editor));
            this.txtTen_Yt = new QMVnSoft.Controls.TextControl();
            this.txtTen_Sp = new QMVnSoft.Controls.TextControl();
            this.txtMa_Yt = new QMVnSoft.Controls.TextSearch();
            this.lblMa_Yt = new QMVnSoft.Controls.LabelControl();
            this.txtMa_Sp = new QMVnSoft.Controls.TextSearch();
            this.lblMa_Sp = new QMVnSoft.Controls.LabelControl();
            this.lblTien = new QMVnSoft.Controls.LabelControl();
            this.txtDu_Cuoi = new QMVnSoft.Controls.TextNumeric();
            this.SuspendLayout();
            // 
            // txtTen_Yt
            // 
            this.txtTen_Yt.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(194)))), ((int)(((byte)(217)))), ((int)(((byte)(247)))));
            this.txtTen_Yt.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.txtTen_Yt.CheckTextSearched = false;
            this.txtTen_Yt.DisabledForeColor = System.Drawing.Color.Blue;
            this.txtTen_Yt.Enabled = false;
            this.txtTen_Yt.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtTen_Yt.ForeColor = System.Drawing.Color.Blue;
            this.txtTen_Yt.Location = new System.Drawing.Point(190, 52);
            this.txtTen_Yt.Name = "txtTen_Yt";
            this.txtTen_Yt.OldValue = null;
            this.txtTen_Yt.Size = new System.Drawing.Size(293, 13);
            this.txtTen_Yt.TabIndex = 79;
            this.txtTen_Yt.UserTextLength  = QMVnSoft.AppInstance.TextControlLength.None;
            this.txtTen_Yt.UserTrimMode  = QMVnSoft.AppInstance.TextControlTrimMode.Right;
            this.txtTen_Yt.Value = ((object)(resources.GetObject("txtTen_Yt.Value")));
            // 
            // txtTen_Sp
            // 
            this.txtTen_Sp.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(194)))), ((int)(((byte)(217)))), ((int)(((byte)(247)))));
            this.txtTen_Sp.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.txtTen_Sp.CheckTextSearched = false;
            this.txtTen_Sp.DisabledForeColor = System.Drawing.Color.Blue;
            this.txtTen_Sp.Enabled = false;
            this.txtTen_Sp.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtTen_Sp.ForeColor = System.Drawing.Color.Blue;
            this.txtTen_Sp.Location = new System.Drawing.Point(190, 31);
            this.txtTen_Sp.Name = "txtTen_Sp";
            this.txtTen_Sp.OldValue = null;
            this.txtTen_Sp.Size = new System.Drawing.Size(293, 13);
            this.txtTen_Sp.TabIndex = 80;
            this.txtTen_Sp.UserTextLength  = QMVnSoft.AppInstance.TextControlLength.None;
            this.txtTen_Sp.UserTrimMode  = QMVnSoft.AppInstance.TextControlTrimMode.Right;
            this.txtTen_Sp.Value = ((object)(resources.GetObject("txtTen_Sp.Value")));
            // 
            // txtMa_Yt
            // 
            this.txtMa_Yt.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
            this.txtMa_Yt.CheckTextSearched = false;
            this.txtMa_Yt.DisabledForeColor = System.Drawing.Color.Empty;
            this.txtMa_Yt.FieldDisplay = "Ten_Yt";
            this.txtMa_Yt.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtMa_Yt.Location = new System.Drawing.Point(73, 49);
            this.txtMa_Yt.MaxLength = 32;
            this.txtMa_Yt.Name = "txtMa_Yt";
            this.txtMa_Yt.OldValue = null;
            this.txtMa_Yt.Size = new System.Drawing.Size(111, 20);
            this.txtMa_Yt.TabIndex = 1;
            this.txtMa_Yt.TableName = "DMYT";
            this.txtMa_Yt.TextDisplay = this.txtTen_Yt;
            this.txtMa_Yt.UserTextLength  = QMVnSoft.AppInstance.TextControlLength.ItemCode;
            this.txtMa_Yt.UserTrimMode  = QMVnSoft.AppInstance.TextControlTrimMode.All;
            this.txtMa_Yt.Value = ((object)(resources.GetObject("txtMa_Yt.Value")));
            // 
            // lblMa_Yt
            // 
            this.lblMa_Yt.AutoSize = true;
            this.lblMa_Yt.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblMa_Yt.Location = new System.Drawing.Point(12, 52);
            this.lblMa_Yt.Name = "lblMa_Yt";
            this.lblMa_Yt.Size = new System.Drawing.Size(39, 14);
            this.lblMa_Yt.TabIndex = 77;
            this.lblMa_Yt.Text = "Yếu tố";
            // 
            // txtMa_Sp
            // 
            this.txtMa_Sp.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
            this.txtMa_Sp.CheckTextSearched = false;
            this.txtMa_Sp.DisabledForeColor = System.Drawing.Color.Empty;
            this.txtMa_Sp.FieldDisplay = "Ten_Sp";
            this.txtMa_Sp.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtMa_Sp.Location = new System.Drawing.Point(73, 28);
            this.txtMa_Sp.MaxLength = 32;
            this.txtMa_Sp.Name = "txtMa_Sp";
            this.txtMa_Sp.OldValue = null;
            this.txtMa_Sp.Size = new System.Drawing.Size(111, 20);
            this.txtMa_Sp.TabIndex = 0;
            this.txtMa_Sp.TableName = "DMSP";
            this.txtMa_Sp.TextDisplay = this.txtTen_Sp;
            this.txtMa_Sp.UserTextLength  = QMVnSoft.AppInstance.TextControlLength.ItemCode;
            this.txtMa_Sp.UserTrimMode  = QMVnSoft.AppInstance.TextControlTrimMode.All;
            this.txtMa_Sp.Value = ((object)(resources.GetObject("txtMa_Sp.Value")));
            // 
            // lblMa_Sp
            // 
            this.lblMa_Sp.AutoSize = true;
            this.lblMa_Sp.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblMa_Sp.Location = new System.Drawing.Point(12, 31);
            this.lblMa_Sp.Name = "lblMa_Sp";
            this.lblMa_Sp.Size = new System.Drawing.Size(55, 14);
            this.lblMa_Sp.TabIndex = 78;
            this.lblMa_Sp.Text = "Sản phẩm";
            // 
            // lblTien
            // 
            this.lblTien.AutoSize = true;
            this.lblTien.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblTien.Location = new System.Drawing.Point(12, 73);
            this.lblTien.Name = "lblTien";
            this.lblTien.Size = new System.Drawing.Size(42, 14);
            this.lblTien.TabIndex = 86;
            this.lblTien.Text = "Dư đầu";
            // 
            // txtDu_Cuoi
            // 
            this.txtDu_Cuoi.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtDu_Cuoi.Location = new System.Drawing.Point(73, 70);
            this.txtDu_Cuoi.Name = "txtDu_Cuoi";
            this.txtDu_Cuoi.NumericValue = new decimal(new int[] {
            0,
            0,
            0,
            0});
            this.txtDu_Cuoi.OldValue = null;
            this.txtDu_Cuoi.Size = new System.Drawing.Size(162, 20);
            this.txtDu_Cuoi.TabIndex = 6;
            this.txtDu_Cuoi.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            this.txtDu_Cuoi.UserTextNumericFormat  = QMVnSoft.AppInstance.TextNumericFormat.LocalAmount;
            this.txtDu_Cuoi.Value = ((object)(resources.GetObject("txtDu_Cuoi.Value")));
            // 
            // FormCDZ3Editor
            // 
            this.AddTitleText = "Thêm giá trị sản phẩm dở dang";
            this.ClientSize = new System.Drawing.Size(495, 158);
            this.Controls.Add(this.txtMa_Sp);
            this.Controls.Add(this.lblTien);
            this.Controls.Add(this.txtDu_Cuoi);
            this.Controls.Add(this.lblMa_Yt);
            this.Controls.Add(this.txtTen_Yt);
            this.Controls.Add(this.txtTen_Sp);
            this.Controls.Add(this.txtMa_Yt);
            this.Controls.Add(this.lblMa_Sp);
            this.EditTitleText = "Sửa giá trị sản phẩm dở dang";
            this.Name = "FormCDZ3Editor";
            this.Text = "Thêm giá trị sản phẩm dở dang";
            this.Controls.SetChildIndex(this.lblMa_Sp, 0);
            this.Controls.SetChildIndex(this.txtMa_Yt, 0);
            this.Controls.SetChildIndex(this.txtTen_Sp, 0);
            this.Controls.SetChildIndex(this.txtTen_Yt, 0);
            this.Controls.SetChildIndex(this.lblMa_Yt, 0);
            this.Controls.SetChildIndex(this.txtDu_Cuoi, 0);
            this.Controls.SetChildIndex(this.lblTien, 0);
            this.Controls.SetChildIndex(this.txtMa_Sp, 0);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        protected override void OnReset()
        {
            if (base.NewChecked)
            {
                this.txtDu_Cuoi.Value = 0;
            }
        }

        public override bool OnSave()
        {
            DataRow localCurrentRow;
            if (((((DateTime) base.UserDefined1) != AppInstance.OpeningDateOfSubEnterprice) || (((DateTime) base.UserDefined2) < AppInstance.OpeningDateOfSubEnterprice)) || (((DateTime) base.UserDefined2) <= AppInstance.EndingDateOfSubEnterprice))
            {
                MessageBox.Show("Đã khóa dữ liệu!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            if (string.IsNullOrEmpty(this.txtMa_Sp.Text))
            {
                MessageBox.Show("Chưa nhập mã sản phẩm!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            if (string.IsNullOrEmpty(this.txtMa_Yt.Text))
            {
                MessageBox.Show("Chưa nhập mã yếu tố!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            if (this.txtDu_Cuoi.NumericValue == 0M)
            {
                MessageBox.Show("Chưa nhập giá trị dở dang đầu kỳ!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            if (base.NewChecked)
            {
                localCurrentRow = base.LocalTable.NewRow();
                localCurrentRow["Ma_Dvcs"] = AppInstance.Subsidiary;
            }
            else
            {
                localCurrentRow = base.LocalCurrentRow;
            }
            localCurrentRow["Ma_Sp"] = this.txtMa_Sp.Value;
            localCurrentRow["Ten_Sp"] = this.txtTen_Sp.Value;
            localCurrentRow["Ma_Yt"] = this.txtMa_Yt.Value;
            localCurrentRow["Ten_Yt"] = this.txtTen_Yt.Value;
            localCurrentRow["Du_Cuoi"] = this.txtDu_Cuoi.Value;
            localCurrentRow["Loai_DD"] = base.UserDefined3;
            localCurrentRow["Ngay_Ct"] = ((DateTime) base.UserDefined1).AddDays(-1.0);
            CDZDataAccess access = new CDZDataAccess();
            if (access.Save(base.NewChecked, localCurrentRow) == -1)
            {
                MessageBox.Show("Đã tồn tại giá trị của yếu tố này!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return false;
            }
            base.SavedMasterOrder = localCurrentRow["Stt"];
            if (base.NewChecked)
            {
                base.LocalTable.Rows.Add(localCurrentRow);
            }
            base.LocalCurrentRow = localCurrentRow;
            base.LocalTable.AcceptChanges();
            this.txtMa_Sp.Focus();
            return base.OnSave();
        }

        public override void OnShow()
        {
            this.txtMa_Sp.Value = base.LocalCurrentRow["Ma_Sp"];
            this.txtTen_Sp.Value = base.LocalCurrentRow["Ten_Sp"];
            this.txtMa_Yt.Value = base.LocalCurrentRow["Ma_Yt"];
            this.txtTen_Yt.Value = base.LocalCurrentRow["Ten_Yt"];
            this.txtDu_Cuoi.Value = base.LocalCurrentRow["Du_Cuoi"];
        }
    }
}

